package com.atguigu.admin.service.impl;

import com.atguigu.admin.bean.City;
import com.atguigu.admin.mapper.CityMapper;
import com.atguigu.admin.service.CityService;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author ：malichun
 * @date 2022/2/9 11:09 AM
 * @description：
 * @modified By：
 */
@Service
public class CityServiceImpl implements CityService {
    @Autowired
    CityMapper cityMapper;

    Counter counter;

    //构造器注入
    public CityServiceImpl(MeterRegistry meterRegistry){
        // 指标注册
        Counter counter = meterRegistry.counter("cityService.saveCity.count");

    }

    public City getById(Long id){
        return cityMapper.getById(id);
    }

    public void saveCity(City city) {
        counter.increment(); // count+1
        cityMapper.insert(city);
    }
}
